package cn.expopay.mail.util;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * 文件操作工具类
 *
 * Created by JJ on 2016/7/13.
 */
public class FileUtils {

    private static Logger logger = LoggerFactory.getLogger(FileUtils.class);

    @SuppressWarnings("Since15")
    public static Properties getProperties(String filePath){
        if(StringUtils.isEmpty(filePath)){
            return null;
        }
        Properties properties = null;
        InputStream inputStream = null;
        try {
            inputStream = FileUtils.class.getResourceAsStream("/" + filePath);
            properties = new Properties();
            properties.load(new InputStreamReader(inputStream,"UTF-8"));
        }catch (Exception e){
            logger.error(e.getMessage());
            throw new RuntimeException(e);
        }finally {
            if(inputStream != null){
                try {
                    inputStream.close();
                }catch (Exception e){
                    logger.error("关闭输入流失败！" + e.getMessage());
                    throw new RuntimeException(e);
                }
            }
        }
        return properties;
    }

}
